<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html >
<html>
<head>
<%@ include file="/WEB-INF/view/include/jQgrid.jsp"%>

</head>
<body style="background-color: white;" class="gray-bg">
                    <div class="ibox-content">
                        <form  class="form-horizontal m-t" id="signupForm">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">用户名：</label>
                                <div class="col-sm-8">
                                    <input id="username" name="username" value="" class="form-control" type="text">
                                    <input name="SKIN" value="default" type="hidden"> 
                                    <input name="state" value="1" type="hidden"> 
                                    <span class="help-block m-b-none"><i class="glyphicon glyphicon-info-sign"></i>用户名是唯一存在</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">姓名：</label>
                                <div class="col-sm-8">
                                    <input id="truename" name="truename" value="" class="form-control" type="text" aria-required="true" aria-invalid="false" class="valid">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">电话号码：</label>
                                <div class="col-sm-8">
                                    <input id="mobile" name="mobile" value="" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">密码：</label>
                                <div class="col-sm-8">
                                    <input id="password" name="password" class="form-control" type="password">
                                    <span class="help-block m-b-none"><i class="glyphicon glyphicon-info-sign"></i>以字母开头，长度在6~18之间，只能包含字母、数字和下划线</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">确认密码：</label>
                                <div class="col-sm-8">
                                    <input id="confirm_password" name="confirm_password" class="form-control" type="password">
                                    <span class="help-block m-b-none"><i class="glyphicon glyphicon-info-sign"></i> 请再次输入您的密码</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">邮箱：</label>
                                <div class="col-sm-8">
                                    <input id="email" name="email" value="" class="form-control" type="email">
                                </div>
                            </div>
                           <div class="form-group">
                                <label class="col-sm-3 control-label">所属部门：</label>
                                <div class="col-sm-8">
                                	<c:if test="${depid!=-1 }">
                                   	<select name="depid"  class="form-control" disabled="disabled">
                                   			<option value="${depb.depId }" selected=selected >${depb.depName }</option>
                                   	</select>
                                   		<input name="depid" value="${depb.depId }" type="hidden">
                                   	</c:if>
                                   	<c:if test="${depid==-1 }">
                                   	<select name="depid"  class="form-control">
                                   		<c:forEach var="dep" items="${dep }" >
                                   			<option value="${dep.depId }" <c:if test="${depid==dep.depId }">selected=selected</c:if> <c:if test="${dep.companyId==0 }"> disabled="disabled"</c:if> ><c:if test="${dep.companyId!=0 }">&nbsp;&nbsp;&nbsp;&nbsp;</c:if>${dep.depName }</option>
                                   		</c:forEach>
                                   	</select>
                                   	</c:if>
                                </div>
                            </div>
                            <div class="form-group" id="addimg">
                                <label class="col-sm-3 control-label">添加图片：</label>
                                <div class="col-sm-8">
                                    <input type="file" name="file" style="display: none;" id="addimgs" onchange="getFileSize(event);" accept="image/*" />
                                    <span style='width: 78px; height: 78px; display: none; cursor: pointer; ' id="imglist"  onclick="$('#addimgs').click();"><img src=''  width='78px' height='78px' id="imgshow"></span>
                                    <span class="picUploadBtn" onclick="$('#addimgs').click();" id="imglist1p" style="border: 1px solid #999999; width: 78px; height: 78px; display: block; cursor: pointer;background-image: url('<%=contextPath%>/static/img/uploadimg.png');"></span>
                                </div>
                            </div>
                            <div class="form-group">
                            <label class="col-sm-3 control-label">拥有角色：</label>
                             <div class="col-sm-8">
                                <select id="roleIds" name="roleIds" data-placeholder="选择角色" class="chosen-select" multiple style="width:100%;" tabindex="4">
                                   <c:forEach var="role" items="${role }">
                                  		 <option value="${role.id }">${role.name }</option>
                                  	</c:forEach>
                                </select>
                             </div>
                            </div>

	                      <%--   <div class="form-group">
	                            <label class="col-sm-3 control-label">所属部门：</label>
	                            <div class="col-sm-8">
	                                <select id="depid" name="depid" data-placeholder="选择部门" class="form-control m-b" tabindex="2">
	                                   <c:forEach items="${dep }" var="deps">
	                                     <option value="${deps.depId }" hassubinfo="true" <c:if test="${deps.pid==0}"> disabled="disabled"</c:if>>${deps.depName }--${deps.parentname}</option> 
	                                   </c:forEach>
	                                </select>
	                            </div>
	                        </div> --%>
	                        <div class="form-group">
                            <label class="col-sm-3 control-label">数据权限：</label>
                             <div class="col-sm-8">
                                <input type="radio" name="datarole" value="0"  />全部
                                <input type="radio" name="datarole" value="1" />公司
                                <input type="radio" name="datarole" value="2" checked="checked"/>个人
                             </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-8 col-sm-offset-3">
                                    <button class="btn btn-primary" type="button" id="sub">提交</button>
                                </div>
                            </div>
                        </form>
                    </div>
	
	
	<script>
	$(function(){
		$('#roleIds').chosen();//下拉框
		$("#sub").click(function(){
			var username = $("#username").val();
			if(username.length==0){
				$("#username").tips({
					side:3,
		            msg:'用户名不能为空！',
		            bg:'#AE81FF',
		            time:1
		        });
				$("#username").focus();
				return;
			}else{
				 $.ajax({
					 url:"<%=contextPath %>/user/getbyname?name="+username,
					 dataType:'json',
					 success:function(data){
						if(!data){
							$("#username").tips({
								side:3,
					            msg:'用户已存在',
					            bg:'#AE81FF',
					            time:1
					        });
							$("#username").focus();
							return;
						}
					 }
				 });
			}
			
			if($("#truename").val().length==0){
				$("#truename").tips({
					side:3,
		            msg:'姓名不能为空！',
		            bg:'#AE81FF',
		            time:1
		        });
				$("#truename").focus();
				return;
			}
			if(!mobile($("#mobile").val(),"#mobile")){
				return;	
			}
			if(!identity($("#password").val(),"#password")){
				return;	
			}
			if($("#confirm_password").val()!=$("#password").val()){
				$("#confirm_password").tips({
					side:3,
		            msg:'两次密码输入不一致！',
		            bg:'#AE81FF',
		            time:1
		        });
				$("#confirm_password").focus();
				return;
			}
			if(!email($("#email").val(),"#email")){
				return;	
			}
			
			if($("#roleIds").val()==null){
				$("#roleIds").tips({
					side:3,
					msg:'请选中角色',
					bg:'#AE81FF',
					time:1
				});
				$("#roleIds").focus();
				return;
			}
			$("#signupForm").ajaxSubmit({
	        	url:'<%=contextPath %>/user/add',
	        	type:'post',
	        	dataType:"json",
	        	success:function(data){
	        		if(data.code==200){
	        			swal({
	        			    title: data.message,
	        			    type: "success",
	        			    showCancelButton: false,
	        			    confirmButtonText: "确定",
	        			    animation:"slide-from-bottom",
	        			    closeOnConfirm: true
	        			},function(){
	        				top.Dialog.close();
	        			});
	        		}else{
	        			swal("错误", data.message, "error");
	        		}
	        	}
	      }); 
			
		});
		
	});
    function getFileSize(evt) {
        var files = evt.target.files;
        var thesrc = window.URL.createObjectURL(files[0]);
        $("#imglist1p").hide();
        $("#imglist").show();
        $("#imgshow").attr("src",thesrc);
    }
	</script>
</body>
</html>